import {routeNames} from "@/router";

/**
 * 生成版面或合集的路由
 * @param isCol 是否为合集的判断方法
 * @param forumId 版面id
 * @param colTid 合集id
 * @returns {{name: *, params: {id: *}}}
 */
export const getForumRoute = (isCol, forumId, colTid) => {
    const name = isCol ? routeNames.thread.colList : routeNames.thread.forumList
    const id = colTid ? colTid : forumId
    return {
        name, params: {id}
    }
}

/**
 * 替换静态资源的前缀
 * @param s 原路径
 * @returns {@link String}
 */
export const replaceResource = (s) => {
    // noinspection HttpUrlsUsage
    return s
        .replace('https://img4.nga.178.com', '/resources')
        .replace('http://img4.nga.cn', '/resources')
        .replace('https://img.nga.178.com', '')
}
/**
 * 判断路由名称是否在列表中
 * @param route 路由
 * @param arr 名称列表
 * @returns {boolean}
 */
export const routeNameIn = (route, ...arr) => {
    if (!arr) {
        return false
    }
    return arr.includes(route.name)
}

